const Router = require('koa-router');
const tool = require("../../tools/tool");
const router = new Router();
const {db, Op, QueryTypes} = require("../../models/db");



// 开销售单 购货单时 查询应收、付余额
router.post('/bill/getYsfYe', async ctx => {
    let transType = tool.xe.toNumber(ctx.request.body.transType)
    let buId = ctx.request.body.buId
    let tenantId = ctx.user.tenantId
    if(transType === 150501) {
        // 查询预付余额
        let m = await db.query(`select ye from v_ye_yuf where tenantId=${tenantId} and buId=${buId} `, {
            type: QueryTypes.SELECT, plain: true
        })
        if(m) {
            return ctx.suc('', m.ye)
        }
    }
    if(transType === 150601) {
        let m = await db.query(`select ye from v_ye_yus where tenantId=${tenantId} and buId=${buId} `, {
            type: QueryTypes.SELECT, plain: true
        })
        if(m) {
            return ctx.suc('', m.ye)
        }
    }
    return ctx.suc('', 0)
})
module.exports = router;